<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-- Copyright 2016 TensorFlow authors.</span><span>
</span><span id="line-2"></span><span class="hs-comment">--</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- you may not use this file except in compliance with the License.</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- You may obtain a copy of the License at</span><span>
</span><span id="line-6"></span><span class="hs-comment">--</span><span>
</span><span id="line-7"></span><span class="hs-comment">--     http://www.apache.org/licenses/LICENSE-2.0</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Unless required by applicable law or agreed to in writing, software</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- See the License for the specific language governing permissions and</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- limitations under the License.</span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-comment">-- | Conduit wrappers for TensorFlow.Records.</span><span>
</span><span id="line-16"></span><span>
</span><span id="line-17"></span><span class="hs-pragma">{-# LANGUAGE Rank2Types #-}</span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">TensorFlow.Records.Conduit</span><span>
</span><span id="line-19"></span><span>  </span><span class="hs-special">(</span><span>
</span><span id="line-20"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Encode/Decode</span></span><span>
</span><span id="line-21"></span><span>    </span><span class="annot"><a href="TensorFlow.Records.Conduit.html#encodeTFRecords"><span class="hs-identifier">encodeTFRecords</span></a></span><span>
</span><span id="line-22"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Records.Conduit.html#decodeTFRecords"><span class="hs-identifier">decodeTFRecords</span></a></span><span>
</span><span id="line-23"></span><span>
</span><span id="line-24"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Source/Sink</span></span><span>
</span><span id="line-25"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Records.Conduit.html#sinkTFRecords"><span class="hs-identifier">sinkTFRecords</span></a></span><span>
</span><span id="line-26"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="TensorFlow.Records.Conduit.html#sourceTFRecords"><span class="hs-identifier">sourceTFRecords</span></a></span><span>
</span><span id="line-27"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad.Catch</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MonadThrow</span></span><span class="hs-special">)</span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Control.Monad.Trans.Resource</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">MonadResource</span></span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.ByteString</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">B</span></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><span class="hs-identifier">Data.ByteString.Lazy</span></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">BL</span></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Conduit</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-operator">(.|)</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">ConduitT</span></span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Conduit.Binary</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">sinkFile</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">sourceFile</span></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">Data.Conduit.Cereal</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">conduitGet2</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">conduitPut</span></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-identifier">TensorFlow.Records</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier">getTFRecord</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier">putTFRecord</span></span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span class="hs-comment">-- | Decode TFRecords from a stream of bytes.</span><span>
</span><span id="line-40"></span><span id="local-6989586621679058088"><span class="annot"><a href="TensorFlow.Records.Conduit.html#decodeTFRecords"><span class="hs-identifier hs-type">decodeTFRecords</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MonadThrow</span></span><span> </span><span class="annot"><a href="#local-6989586621679058088"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ConduitT</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">BL.ByteString</span></span><span> </span><span class="annot"><a href="#local-6989586621679058088"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-41"></span><span id="decodeTFRecords"><span class="annot"><span class="annottext">decodeTFRecords :: ConduitT ByteString ByteString m ()
</span><a href="TensorFlow.Records.Conduit.html#decodeTFRecords"><span class="hs-identifier hs-var hs-var">decodeTFRecords</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Get ByteString -&gt; ConduitT ByteString ByteString m ()
forall (m :: * -&gt; *) o.
MonadThrow m =&gt;
Get o -&gt; ConduitT ByteString o m ()
</span><span class="hs-identifier hs-var">conduitGet2</span></span><span> </span><span class="annot"><span class="annottext">Get ByteString
</span><span class="hs-identifier hs-var">getTFRecord</span></span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-comment">-- | Read TFRecords from a file.</span><span>
</span><span id="line-44"></span><span id="local-6989586621679058066"><span id="local-6989586621679058067"><span class="annot"><a href="TensorFlow.Records.Conduit.html#sourceTFRecords"><span class="hs-identifier hs-type">sourceTFRecords</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">MonadResource</span></span><span> </span><span class="annot"><a href="#local-6989586621679058067"><span class="hs-identifier hs-type">m</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="hs-identifier hs-type">MonadThrow</span></span><span> </span><span class="annot"><a href="#local-6989586621679058067"><span class="hs-identifier hs-type">m</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FilePath</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ConduitT</span></span><span> </span><span class="annot"><a href="#local-6989586621679058066"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">BL.ByteString</span></span><span> </span><span class="annot"><a href="#local-6989586621679058067"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-45"></span><span id="sourceTFRecords"><span class="annot"><span class="annottext">sourceTFRecords :: FilePath -&gt; ConduitT i ByteString m ()
</span><a href="TensorFlow.Records.Conduit.html#sourceTFRecords"><span class="hs-identifier hs-var hs-var">sourceTFRecords</span></a></span></span><span> </span><span id="local-6989586621679058065"><span class="annot"><span class="annottext">path :: FilePath
</span><a href="#local-6989586621679058065"><span class="hs-identifier hs-var">path</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; ConduitT i ByteString m ()
forall (m :: * -&gt; *) i.
MonadResource m =&gt;
FilePath -&gt; ConduitT i ByteString m ()
</span><span class="hs-identifier hs-var">sourceFile</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679058065"><span class="hs-identifier hs-var">path</span></a></span><span> </span><span class="annot"><span class="annottext">ConduitT i ByteString m ()
-&gt; ConduitM ByteString ByteString m ()
-&gt; ConduitT i ByteString m ()
forall (m :: * -&gt; *) a b c r.
Monad m =&gt;
ConduitM a b m () -&gt; ConduitM b c m r -&gt; ConduitM a c m r
</span><span class="hs-operator hs-var">.|</span></span><span> </span><span class="annot"><span class="annottext">ConduitM ByteString ByteString m ()
forall (m :: * -&gt; *).
MonadThrow m =&gt;
ConduitT ByteString ByteString m ()
</span><a href="TensorFlow.Records.Conduit.html#decodeTFRecords"><span class="hs-identifier hs-var">decodeTFRecords</span></a></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span class="hs-comment">-- | Encode TFRecords to a stream of bytes.</span><span>
</span><span id="line-48"></span><span id="local-6989586621679058081"><span class="annot"><a href="TensorFlow.Records.Conduit.html#encodeTFRecords"><span class="hs-identifier hs-type">encodeTFRecords</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Monad</span></span><span> </span><span class="annot"><a href="#local-6989586621679058081"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ConduitT</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">BL.ByteString</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">B.ByteString</span></span><span> </span><span class="annot"><a href="#local-6989586621679058081"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-49"></span><span id="encodeTFRecords"><span class="annot"><span class="annottext">encodeTFRecords :: ConduitT ByteString ByteString m ()
</span><a href="TensorFlow.Records.Conduit.html#encodeTFRecords"><span class="hs-identifier hs-var hs-var">encodeTFRecords</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Putter ByteString -&gt; ConduitT ByteString ByteString m ()
forall (m :: * -&gt; *) a.
Monad m =&gt;
Putter a -&gt; ConduitT a ByteString m ()
</span><span class="hs-identifier hs-var">conduitPut</span></span><span> </span><span class="annot"><span class="annottext">Putter ByteString
</span><span class="hs-identifier hs-var">putTFRecord</span></span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-comment">-- | Write TFRecords to a file.</span><span>
</span><span id="line-52"></span><span id="local-6989586621679058063"><span id="local-6989586621679058064"><span class="annot"><a href="TensorFlow.Records.Conduit.html#sinkTFRecords"><span class="hs-identifier hs-type">sinkTFRecords</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="hs-identifier hs-type">MonadResource</span></span><span> </span><span class="annot"><a href="#local-6989586621679058064"><span class="hs-identifier hs-type">m</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">FilePath</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">ConduitT</span></span><span> </span><span class="annot"><span class="hs-identifier hs-type">BL.ByteString</span></span><span> </span><span class="annot"><a href="#local-6989586621679058063"><span class="hs-identifier hs-type">o</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679058064"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-53"></span><span id="sinkTFRecords"><span class="annot"><span class="annottext">sinkTFRecords :: FilePath -&gt; ConduitT ByteString o m ()
</span><a href="TensorFlow.Records.Conduit.html#sinkTFRecords"><span class="hs-identifier hs-var hs-var">sinkTFRecords</span></a></span></span><span> </span><span id="local-6989586621679058062"><span class="annot"><span class="annottext">path :: FilePath
</span><a href="#local-6989586621679058062"><span class="hs-identifier hs-var">path</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ConduitT ByteString ByteString m ()
forall (m :: * -&gt; *).
Monad m =&gt;
ConduitT ByteString ByteString m ()
</span><a href="TensorFlow.Records.Conduit.html#encodeTFRecords"><span class="hs-identifier hs-var">encodeTFRecords</span></a></span><span> </span><span class="annot"><span class="annottext">ConduitT ByteString ByteString m ()
-&gt; ConduitM ByteString o m () -&gt; ConduitT ByteString o m ()
forall (m :: * -&gt; *) a b c r.
Monad m =&gt;
ConduitM a b m () -&gt; ConduitM b c m r -&gt; ConduitM a c m r
</span><span class="hs-operator hs-var">.|</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; ConduitM ByteString o m ()
forall (m :: * -&gt; *) o.
MonadResource m =&gt;
FilePath -&gt; ConduitT ByteString o m ()
</span><span class="hs-identifier hs-var">sinkFile</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679058062"><span class="hs-identifier hs-var">path</span></a></span><span>
</span><span id="line-54"></span></pre></body></html>